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 hadronic/Hadr01/src/DetectorConstruc 26 /// \file hadronic/Hadr01/src/DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConst 27 /// \brief Implementation of the DetectorConstruction class 28 // 28 // 29 // 29 // 30 ////////////////////////////////////////////// 30 ///////////////////////////////////////////////////////////////////////// 31 // 31 // 32 // DetectorConstruction 32 // DetectorConstruction 33 // 33 // 34 // Created: 31.01.2003 V.Ivanchenko 34 // Created: 31.01.2003 V.Ivanchenko 35 // 35 // 36 // Modified: 36 // Modified: 37 // 04.06.2006 Adoptation of Hadr01 (V.Ivanchen 37 // 04.06.2006 Adoptation of Hadr01 (V.Ivanchenko) 38 // 38 // 39 ////////////////////////////////////////////// 39 //////////////////////////////////////////////////////////////////////// 40 // << 40 // 41 41 42 #include "DetectorConstruction.hh" 42 #include "DetectorConstruction.hh" 43 << 44 #include "CheckVolumeSD.hh" << 45 #include "DetectorMessenger.hh" 43 #include "DetectorMessenger.hh" 46 #include "HistoManager.hh" << 47 #include "TargetSD.hh" << 48 44 49 #include "G4Colour.hh" << 45 #include "G4Tubs.hh" 50 #include "G4GeometryManager.hh" << 51 #include "G4LogicalVolume.hh" 46 #include "G4LogicalVolume.hh" 52 #include "G4LogicalVolumeStore.hh" << 53 #include "G4NistManager.hh" << 54 #include "G4PVPlacement.hh" 47 #include "G4PVPlacement.hh" 55 #include "G4PhysicalConstants.hh" << 48 56 #include "G4PhysicalVolumeStore.hh" << 57 #include "G4RunManager.hh" 49 #include "G4RunManager.hh" 58 #include "G4SDManager.hh" << 50 >> 51 #include "G4GeometryManager.hh" >> 52 #include "G4PhysicalVolumeStore.hh" >> 53 #include "G4LogicalVolumeStore.hh" 59 #include "G4SolidStore.hh" 54 #include "G4SolidStore.hh" 60 #include "G4SystemOfUnits.hh" << 55 61 #include "G4Tubs.hh" << 62 #include "G4UnitsTable.hh" << 63 #include "G4VisAttributes.hh" 56 #include "G4VisAttributes.hh" >> 57 #include "G4Colour.hh" >> 58 >> 59 #include "G4UnitsTable.hh" 64 #include "G4ios.hh" 60 #include "G4ios.hh" 65 61 >> 62 #include "TargetSD.hh" >> 63 #include "CheckVolumeSD.hh" >> 64 #include "G4SDManager.hh" >> 65 #include "HistoManager.hh" >> 66 #include "G4NistManager.hh" >> 67 >> 68 #include "G4PhysicalConstants.hh" >> 69 #include "G4SystemOfUnits.hh" >> 70 >> 71 66 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 67 73 68 DetectorConstruction::DetectorConstruction() 74 DetectorConstruction::DetectorConstruction() 69 : G4VUserDetectorConstruction(), << 75 : G4VUserDetectorConstruction(), 70 fTargetMaterial(nullptr), << 76 fTargetMaterial(nullptr), 71 fWorldMaterial(nullptr), << 77 fWorldMaterial(nullptr), 72 fSolidW(nullptr), << 78 fSolidW(nullptr), 73 fSolidA(nullptr), << 79 fSolidA(nullptr), 74 fSolidC(nullptr), << 80 fSolidC(nullptr), 75 fLogicTarget(nullptr), << 81 fLogicTarget(nullptr), 76 fLogicCheck(nullptr), << 82 fLogicCheck(nullptr), 77 fLogicWorld(nullptr), << 83 fLogicWorld(nullptr), 78 fPhysWorld(nullptr), << 84 fPhysWorld(nullptr), 79 fInitialized(false) << 85 fInitialized(false) 80 { 86 { 81 fDetectorMessenger = new DetectorMessenger(t 87 fDetectorMessenger = new DetectorMessenger(this); >> 88 >> 89 fRadius = 10.*cm; >> 90 82 G4NistManager* nist = G4NistManager::Instanc 91 G4NistManager* nist = G4NistManager::Instance(); 83 fTargetMaterial = nist->FindOrBuildMaterial( 92 fTargetMaterial = nist->FindOrBuildMaterial("G4_Al"); 84 fWorldMaterial = nist->FindOrBuildMaterial(" << 93 fWorldMaterial = nist->FindOrBuildMaterial("G4_Galactic"); >> 94 85 // 95 // 86 // define battery material using Bugzilla 21 96 // define battery material using Bugzilla 2175 data 87 // 97 // 88 G4Element* elH = nist->FindOrBuildElement(1) << 98 G4Element* elH = nist->FindOrBuildElement(1); 89 G4Element* elLi = nist->FindOrBuildElement(3 99 G4Element* elLi = nist->FindOrBuildElement(3); 90 G4Element* elC = nist->FindOrBuildElement(6) << 100 G4Element* elC = nist->FindOrBuildElement(6); 91 G4Element* elO = nist->FindOrBuildElement(8) << 101 G4Element* elO = nist->FindOrBuildElement(8); 92 G4Element* elAl = nist->FindOrBuildElement(1 102 G4Element* elAl = nist->FindOrBuildElement(13); 93 G4Element* elTi = nist->FindOrBuildElement(2 103 G4Element* elTi = nist->FindOrBuildElement(22); 94 G4Element* elCo = nist->FindOrBuildElement(2 104 G4Element* elCo = nist->FindOrBuildElement(27); 95 G4Element* elCu = nist->FindOrBuildElement(2 105 G4Element* elCu = nist->FindOrBuildElement(29); 96 G4Material* bat = new G4Material("Battery", << 106 G4Material* bat = new G4Material("Battery",2.165*CLHEP::g/CLHEP::cm3,8); 97 bat->AddElement(elC, 0.19518445618745); << 107 bat->AddElement(elC, 0.19518445618745); 98 bat->AddElement(elAl, 0.398); 108 bat->AddElement(elAl, 0.398); 99 bat->AddElement(elTi, 0.02); 109 bat->AddElement(elTi, 0.02); 100 bat->AddElement(elCu, 0.084); 110 bat->AddElement(elCu, 0.084); 101 bat->AddElement(elLi, 0.0170098229419813); 111 bat->AddElement(elLi, 0.0170098229419813); 102 bat->AddElement(elCo, 0.144570016541753); 112 bat->AddElement(elCo, 0.144570016541753); 103 bat->AddElement(elO, 0.134206611504321); << 113 bat->AddElement(elO, 0.134206611504321); 104 bat->AddElement(elH, 0.0070290928244947); << 114 bat->AddElement(elH, 0.0070290928244947); 105 bat->GetIonisation()->SetMeanExcitationEnerg << 115 bat->GetIonisation()->SetMeanExcitationEnergy(144.88*eV); 106 116 107 ComputeGeomParameters(); 117 ComputeGeomParameters(); 108 } 118 } 109 119 110 //....oooOO0OOooo........oooOO0OOooo........oo 120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 111 121 112 DetectorConstruction::~DetectorConstruction() 122 DetectorConstruction::~DetectorConstruction() 113 { << 123 { 114 delete fDetectorMessenger; 124 delete fDetectorMessenger; 115 } 125 } 116 126 117 void DetectorConstruction::ComputeGeomParamete 127 void DetectorConstruction::ComputeGeomParameters() 118 { 128 { 119 HistoManager* histo = HistoManager::GetPoint << 120 // Sizes 129 // Sizes 121 fRadius = histo->Radius(); << 130 fCheckR = fRadius + CLHEP::mm; 122 fCheckR = fRadius + CLHEP::mm; << 131 fWorldR = fRadius + CLHEP::cm; 123 fWorldR = fRadius + CLHEP::cm; << 132 fTargetZ = HistoManager::GetPointer()->Length()*0.5; 124 fTargetZ = histo->Length() * 0.5; << 133 fCheckZ = fTargetZ + CLHEP::mm; 125 fCheckZ = fTargetZ + CLHEP::mm; << 134 fWorldZ = fTargetZ + CLHEP::cm; 126 fWorldZ = fTargetZ + CLHEP::cm; << 135 127 << 136 fSlices = HistoManager::GetPointer()->NumberOfSlices(); 128 fSlices = histo->NumberOfSlices(); << 137 fSliceZ = fTargetZ/G4double(fSlices); 129 fSliceZ = fTargetZ / G4double(fSlices); << 138 if(fPhysWorld) { 130 if (fPhysWorld) { << 131 fSolidW->SetOuterRadius(fWorldR); 139 fSolidW->SetOuterRadius(fWorldR); 132 fSolidW->SetZHalfLength(fWorldZ); 140 fSolidW->SetZHalfLength(fWorldZ); 133 fSolidA->SetOuterRadius(fRadius); 141 fSolidA->SetOuterRadius(fRadius); 134 fSolidA->SetZHalfLength(fSliceZ); 142 fSolidA->SetZHalfLength(fSliceZ); 135 fSolidC->SetOuterRadius(fCheckR); 143 fSolidC->SetOuterRadius(fCheckR); 136 fSolidC->SetZHalfLength(fCheckZ); 144 fSolidC->SetZHalfLength(fCheckZ); 137 } 145 } 138 } 146 } 139 147 140 G4VPhysicalVolume* DetectorConstruction::Const 148 G4VPhysicalVolume* DetectorConstruction::Construct() 141 { 149 { 142 if (nullptr != fPhysWorld) { << 150 if(fPhysWorld) { return fPhysWorld; } 143 return fPhysWorld; << 144 } << 145 ComputeGeomParameters(); 151 ComputeGeomParameters(); 146 152 147 // 153 // 148 // World 154 // World 149 // 155 // 150 fSolidW = new G4Tubs("World", 0., fWorldR, f << 156 fSolidW = new G4Tubs("World",0.,fWorldR,fWorldZ,0.,twopi); 151 fLogicWorld = new G4LogicalVolume(fSolidW, f 157 fLogicWorld = new G4LogicalVolume(fSolidW, fWorldMaterial, "World"); 152 fPhysWorld = << 158 fPhysWorld = new G4PVPlacement(nullptr,G4ThreeVector(0.,0.,0.), 153 new G4PVPlacement(nullptr, G4ThreeVector(0 << 159 fLogicWorld,"World",nullptr,false,0); 154 // 160 // 155 // Check volume 161 // Check volume 156 // 162 // 157 fSolidC = new G4Tubs("Check", 0., fCheckR, f << 163 fSolidC = new G4Tubs("Check",0.,fCheckR,fCheckZ,0.,twopi); 158 fLogicCheck = new G4LogicalVolume(fSolidC, f << 164 fLogicCheck = new G4LogicalVolume(fSolidC, fWorldMaterial, "Check"); 159 new G4PVPlacement(nullptr, G4ThreeVector(0., << 165 new G4PVPlacement(nullptr,G4ThreeVector(),fLogicCheck,"Check", 160 0); << 166 fLogicWorld,false,0); 161 167 162 // 168 // 163 // Target volume 169 // Target volume 164 // 170 // 165 fSolidA = new G4Tubs("Target", 0., fRadius, << 171 fSolidA = new G4Tubs("Target",0.,fRadius,fSliceZ,0.,twopi); 166 fLogicTarget = new G4LogicalVolume(fSolidA, << 172 fLogicTarget = new G4LogicalVolume(fSolidA,fTargetMaterial,"Target"); 167 173 168 G4double z = fSliceZ - fTargetZ; 174 G4double z = fSliceZ - fTargetZ; 169 175 170 for (G4int i = 0; i < fSlices; ++i) { << 176 for(G4int i=0; i<fSlices; ++i) { 171 // physC = << 177 // physC = 172 new G4PVPlacement(nullptr, G4ThreeVector(0 << 178 new G4PVPlacement(nullptr,G4ThreeVector(0.0,0.0,z),fLogicTarget,"Target", 173 false, i); << 179 fLogicCheck,false,i); 174 z += 2.0 * fSliceZ; << 180 z += 2.0*fSliceZ; 175 } 181 } 176 G4cout << "### Target consist of " << fSlice << 182 G4cout << "### Target consist of " << fSlices 177 << " with R(mm)= " << fRadius / mm << << 183 << " disks of " << fTargetMaterial->GetName() 178 << " Total Length(mm)= " << 2.0 * fT << 184 << " with R(mm)= " << fRadius/mm >> 185 << " Width(mm)= " << 2.0*fSliceZ/mm >> 186 << " Total Length(mm)= " << 2.0*fTargetZ/mm >> 187 << " ###" << G4endl; 179 188 180 // colors 189 // colors 181 G4VisAttributes zero = G4VisAttributes::GetI 190 G4VisAttributes zero = G4VisAttributes::GetInvisible(); 182 fLogicWorld->SetVisAttributes(zero); 191 fLogicWorld->SetVisAttributes(zero); 183 192 184 G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 193 G4VisAttributes regWcolor(G4Colour(0.3, 0.3, 0.3)); 185 fLogicCheck->SetVisAttributes(regWcolor); 194 fLogicCheck->SetVisAttributes(regWcolor); 186 195 187 G4VisAttributes regCcolor(G4Colour(0., 0.3, 196 G4VisAttributes regCcolor(G4Colour(0., 0.3, 0.7)); 188 fLogicTarget->SetVisAttributes(regCcolor); 197 fLogicTarget->SetVisAttributes(regCcolor); 189 198 190 G4cout << *(G4Material::GetMaterialTable()) 199 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 191 200 192 return fPhysWorld; 201 return fPhysWorld; 193 } 202 } 194 203 195 void DetectorConstruction::ConstructSDandField 204 void DetectorConstruction::ConstructSDandField() 196 { 205 { 197 if (!fInitialized) { 206 if (!fInitialized) { 198 // Prepare sensitive detectors 207 // Prepare sensitive detectors 199 CheckVolumeSD* fCheckSD = new CheckVolumeS 208 CheckVolumeSD* fCheckSD = new CheckVolumeSD("checkSD"); 200 (G4SDManager::GetSDMpointer())->AddNewDete << 209 (G4SDManager::GetSDMpointer())->AddNewDetector( fCheckSD ); 201 fLogicCheck->SetSensitiveDetector(fCheckSD 210 fLogicCheck->SetSensitiveDetector(fCheckSD); 202 211 203 TargetSD* fTargetSD = new TargetSD("target 212 TargetSD* fTargetSD = new TargetSD("targetSD"); 204 (G4SDManager::GetSDMpointer())->AddNewDete << 213 (G4SDManager::GetSDMpointer())->AddNewDetector( fTargetSD ); 205 fLogicTarget->SetSensitiveDetector(fTarget 214 fLogicTarget->SetSensitiveDetector(fTargetSD); 206 fInitialized = true; 215 fInitialized = true; 207 } 216 } 208 } 217 } 209 //....oooOO0OOooo........oooOO0OOooo........oo 218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 210 219 211 void DetectorConstruction::SetTargetMaterial(c 220 void DetectorConstruction::SetTargetMaterial(const G4String& mat) 212 { 221 { 213 // search the material by its name 222 // search the material by its name 214 G4Material* material = G4NistManager::Instan 223 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat); 215 224 216 if (material && material != fTargetMaterial) 225 if (material && material != fTargetMaterial) { 217 fTargetMaterial = material; 226 fTargetMaterial = material; 218 if (fLogicTarget) { << 227 if(fLogicTarget) { fLogicTarget->SetMaterial(fTargetMaterial); } 219 fLogicTarget->SetMaterial(fTargetMateria << 220 } << 221 G4RunManager::GetRunManager()->PhysicsHasB 228 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 222 } 229 } 223 } 230 } 224 231 225 //....oooOO0OOooo........oooOO0OOooo........oo 232 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 226 233 227 void DetectorConstruction::SetWorldMaterial(co 234 void DetectorConstruction::SetWorldMaterial(const G4String& mat) 228 { 235 { 229 // search the material by its name 236 // search the material by its name 230 G4Material* material = G4NistManager::Instan 237 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat); 231 238 232 if (material && material != fWorldMaterial) 239 if (material && material != fWorldMaterial) { 233 fWorldMaterial = material; 240 fWorldMaterial = material; 234 if (fLogicWorld) { << 241 if(fLogicWorld) { fLogicWorld->SetMaterial(fWorldMaterial); } 235 fLogicWorld->SetMaterial(fWorldMaterial) << 236 } << 237 G4RunManager::GetRunManager()->PhysicsHasB 242 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); >> 243 } >> 244 } >> 245 >> 246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 247 >> 248 void DetectorConstruction::SetTargetRadius(G4double val) >> 249 { >> 250 if(val > 0.0) { >> 251 fRadius = val; >> 252 ComputeGeomParameters(); 238 } 253 } 239 } 254 } 240 255 241 //....oooOO0OOooo........oooOO0OOooo........oo 256 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 242 257