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 medical/fanoCavity/src/DetectorConst 26 /// \file medical/fanoCavity/src/DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConst 27 /// \brief Implementation of the DetectorConstruction class 28 // 28 // >> 29 // $Id: DetectorConstruction.cc 68459 2013-03-27 18:45:08Z maire $ 29 30 30 // 31 // 31 //....oooOO0OOooo........oooOO0OOooo........oo 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 //....oooOO0OOooo........oooOO0OOooo........oo 33 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 34 34 #include "DetectorConstruction.hh" 35 #include "DetectorConstruction.hh" 35 << 36 #include "DetectorMessenger.hh" 36 #include "DetectorMessenger.hh" 37 37 38 #include "G4GeometryManager.hh" << 39 #include "G4LogicalVolume.hh" << 40 #include "G4LogicalVolumeStore.hh" << 41 #include "G4Material.hh" 38 #include "G4Material.hh" 42 #include "G4NistManager.hh" << 39 #include "G4Tubs.hh" >> 40 #include "G4LogicalVolume.hh" >> 41 #include "G4VPhysicalVolume.hh" 43 #include "G4PVPlacement.hh" 42 #include "G4PVPlacement.hh" 44 #include "G4PhysicalConstants.hh" << 43 >> 44 #include "G4GeometryManager.hh" 45 #include "G4PhysicalVolumeStore.hh" 45 #include "G4PhysicalVolumeStore.hh" >> 46 #include "G4LogicalVolumeStore.hh" 46 #include "G4SolidStore.hh" 47 #include "G4SolidStore.hh" 47 #include "G4SystemOfUnits.hh" << 48 48 #include "G4Tubs.hh" << 49 #include "G4UnitsTable.hh" 49 #include "G4UnitsTable.hh" 50 #include "G4VPhysicalVolume.hh" << 50 #include "G4PhysicalConstants.hh" >> 51 #include "G4SystemOfUnits.hh" 51 52 52 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 54 54 DetectorConstruction::DetectorConstruction() : << 55 DetectorConstruction::DetectorConstruction() >> 56 :fWallMaterial(0),fWall(0),fCavityMaterial(0),fCavity(0),fDetectorMessenger(0) 55 { 57 { 56 // default parameter values 58 // default parameter values 57 fCavityThickness = 2 * mm; << 59 fCavityThickness = 2*mm; 58 fCavityRadius = 1 * cm; << 60 fCavityRadius = 1*cm; 59 << 61 60 fWallThickness = 5 * mm; << 62 fWallThickness = 5*mm; 61 << 63 62 DefineMaterials(); 64 DefineMaterials(); 63 SetWallMaterial("G4_WATER"); << 65 SetWallMaterial("Water"); 64 SetCavityMaterial("g4Water_gas"); << 66 SetCavityMaterial("Water_vapor"); 65 << 67 66 // create commands for interactive definitio << 68 // create commands for interactive definition of the detector 67 fDetectorMessenger = new DetectorMessenger(t 69 fDetectorMessenger = new DetectorMessenger(this); 68 } 70 } 69 71 70 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 71 73 72 DetectorConstruction::~DetectorConstruction() 74 DetectorConstruction::~DetectorConstruction() >> 75 { delete fDetectorMessenger;} >> 76 >> 77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 78 >> 79 G4VPhysicalVolume* DetectorConstruction::Construct() 73 { 80 { 74 delete fDetectorMessenger; << 81 return ConstructVolumes(); 75 } 82 } 76 83 77 //....oooOO0OOooo........oooOO0OOooo........oo 84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 78 85 79 void DetectorConstruction::DefineMaterials() 86 void DetectorConstruction::DefineMaterials() 80 { << 87 { 81 G4double z, a; << 88 // 82 << 89 // define Elements 83 G4Element* H = new G4Element("Hydrogen", "H" << 90 // 84 G4Element* O = new G4Element("Oxygen", "O", << 91 G4double z,a; >> 92 >> 93 G4Element* H = new G4Element("Hydrogen" ,"H" , z= 1., a= 1.01*g/mole); >> 94 G4Element* N = new G4Element("Nitrogen" ,"N" , z= 7., a= 14.01*g/mole); >> 95 G4Element* O = new G4Element("Oxygen" ,"O" , z= 8., a= 16.00*g/mole); 85 96 86 G4Material* H2O = new G4Material("Water", 1. << 97 // >> 98 // define materials >> 99 // >> 100 G4Material* H2O = >> 101 new G4Material("Water", 1.0*g/cm3, 2); 87 H2O->AddElement(H, 2); 102 H2O->AddElement(H, 2); 88 H2O->AddElement(O, 1); 103 H2O->AddElement(O, 1); 89 H2O->GetIonisation()->SetMeanExcitationEnerg << 104 H2O->GetIonisation()->SetMeanExcitationEnergy(78.0*eV); 90 << 105 91 G4Material* gas = new G4Material("Water_gas" << 106 G4Material* vapor = 92 gas->AddElement(H, 2); << 107 new G4Material("Water_vapor", 1.0*mg/cm3, 2); 93 gas->AddElement(O, 1); << 108 vapor->AddElement(H, 2); 94 gas->GetIonisation()->SetMeanExcitationEnerg << 109 vapor->AddElement(O, 1); 95 << 110 vapor->GetIonisation()->SetMeanExcitationEnergy(78.0*eV); 96 new G4Material("Graphite", 6, 12.01 * g / mo << 111 97 new G4Material("Graphite_gas", 6, 12.01 * g << 112 G4Material* Air = 98 << 113 new G4Material("Air", 1.290*mg/cm3, 2); 99 new G4Material("Aluminium", 13, 26.98 * g / << 114 Air->AddElement(N, 70.*perCent); 100 new G4Material("Aluminium_gas", 13, 26.98 * << 115 Air->AddElement(O, 30.*perCent); 101 << 116 102 // alternatively, use G4 data base << 117 new G4Material("Graphite", 6, 12.01*g/mole, 2.265*g/cm3); 103 // << 118 new G4Material("Graphite_gas", 6, 12.01*g/mole, 2.265*mg/cm3); 104 G4NistManager* nist = G4NistManager::Instanc << 119 105 << 120 new G4Material("Aluminium", 13, 26.98*g/mole, 2.700*g/cm3); 106 nist->FindOrBuildMaterial("G4_WATER"); << 121 new G4Material("Aluminium_gas", 13, 26.98*g/mole, 2.700*mg/cm3); 107 nist->BuildMaterialWithNewDensity("g4Water_g << 122 108 << 123 G4cout << *(G4Material::GetMaterialTable()) << G4endl; 109 // printout << 110 G4cout << *(G4Material::GetMaterialTable()) << 111 } 124 } 112 125 113 //....oooOO0OOooo........oooOO0OOooo........oo 126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 114 << 127 115 G4VPhysicalVolume* DetectorConstruction::Const << 128 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 116 { << 129 { 117 if (fWall) { << 130 G4GeometryManager::GetInstance()->OpenGeometry(); 118 return fWall; << 131 G4PhysicalVolumeStore::GetInstance()->Clean(); 119 } << 132 G4LogicalVolumeStore::GetInstance()->Clean(); 120 << 133 G4SolidStore::GetInstance()->Clean(); >> 134 121 // Chamber 135 // Chamber 122 // 136 // 123 fTotalThickness = fCavityThickness + 2 * fWa << 137 fTotalThickness = fCavityThickness + 2*fWallThickness; 124 fWallRadius = fCavityRadius + fWallThickness << 138 fWallRadius = fCavityRadius + fWallThickness; 125 << 139 126 G4Tubs* sChamber = new G4Tubs("Chamber", // << 140 G4Tubs* 127 0., fWallRadiu << 141 sChamber = new G4Tubs("Chamber", //name 128 << 142 0.,fWallRadius,0.5*fTotalThickness,0.,twopi); //size 129 G4LogicalVolume* lChamber = new G4LogicalVol << 143 130 << 144 G4LogicalVolume* 131 << 145 lChamber = new G4LogicalVolume(sChamber, //solid 132 << 146 fWallMaterial, //material 133 fWall = new G4PVPlacement(0, // no rotation << 147 "Chamber"); //name 134 G4ThreeVector(), << 148 135 lChamber, // logi << 149 fWall = new G4PVPlacement(0, //no rotation 136 "Wall", // name << 150 G4ThreeVector(), //at (0,0,0) 137 0, // mother vol << 151 lChamber, //logical volume 138 false, // no bool << 152 "Wall", //name 139 0); // copy numbe << 153 0, //mother volume >> 154 false, //no boolean operation >> 155 0); //copy number 140 156 141 // Cavity 157 // Cavity 142 // << 158 // 143 G4Tubs* sCavity = new G4Tubs("Cavity", 0., f << 159 G4Tubs* 144 << 160 sCavity = new G4Tubs("Cavity", 145 G4LogicalVolume* lCavity = new G4LogicalVolu << 161 0.,fCavityRadius,0.5*fCavityThickness,0.,twopi); 146 << 162 147 << 163 G4LogicalVolume* 148 << 164 lCavity = new G4LogicalVolume(sCavity, //shape 149 fCavity = new G4PVPlacement(0, // no rotati << 165 fCavityMaterial, //material 150 G4ThreeVector(), << 166 "Cavity"); //name 151 lCavity, // log << 167 152 "Cavity", // na << 168 fCavity = new G4PVPlacement(0, //no rotation 153 lChamber, // mo << 169 G4ThreeVector(), //at (0,0,0) 154 false, // no bo << 170 lCavity, //logical volume 155 1); // copy num << 171 "Cavity", //name 156 << 172 lChamber, //mother volume >> 173 false, //no boolean operation >> 174 1); //copy number >> 175 157 PrintParameters(); 176 PrintParameters(); 158 << 177 159 // << 160 // always return the root volume << 161 // 178 // >> 179 //always return the root volume >> 180 // 162 return fWall; 181 return fWall; 163 } 182 } 164 183 165 //....oooOO0OOooo........oooOO0OOooo........oo 184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 166 185 167 void DetectorConstruction::PrintParameters() 186 void DetectorConstruction::PrintParameters() 168 { 187 { 169 G4cout << "\n------------------------------- 188 G4cout << "\n---------------------------------------------------------\n"; 170 G4cout << "---> The Wall is " << G4BestUnit( << 189 G4cout << "---> The Wall is " << G4BestUnit(fWallThickness,"Length") 171 << fWallMaterial->GetName() << " ( " << 190 << " of " << fWallMaterial->GetName() << " ( " 172 << G4BestUnit(fWallMaterial->GetDensi << 191 << G4BestUnit(fWallMaterial->GetDensity(),"Volumic Mass") << " )\n"; 173 G4cout << " The Cavity is " << G4BestUni << 192 G4cout << " The Cavity is " << G4BestUnit(fCavityThickness,"Length") 174 << fCavityMaterial->GetName() << " ( << 193 << " of " << fCavityMaterial->GetName() << " ( " 175 << G4BestUnit(fCavityMaterial->GetDen << 194 << G4BestUnit(fCavityMaterial->GetDensity(),"Volumic Mass") << " )"; 176 G4cout << "\n------------------------------- 195 G4cout << "\n---------------------------------------------------------\n"; 177 G4cout << G4endl; 196 G4cout << G4endl; 178 } 197 } 179 198 180 //....oooOO0OOooo........oooOO0OOooo........oo 199 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 181 200 182 void DetectorConstruction::SetWallThickness(G4 201 void DetectorConstruction::SetWallThickness(G4double value) 183 { 202 { 184 fWallThickness = value; 203 fWallThickness = value; 185 } 204 } 186 << 205 187 //....oooOO0OOooo........oooOO0OOooo........oo 206 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 188 207 189 void DetectorConstruction::SetWallMaterial(con << 208 void DetectorConstruction::SetWallMaterial(G4String materialChoice) 190 { 209 { 191 // search the material by its name << 210 // search the material by its name 192 G4Material* pttoMaterial = G4Material::GetMa << 211 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); 193 if (pttoMaterial) fWallMaterial = pttoMateri 212 if (pttoMaterial) fWallMaterial = pttoMaterial; 194 } 213 } 195 214 196 //....oooOO0OOooo........oooOO0OOooo........oo 215 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 197 216 198 void DetectorConstruction::SetCavityThickness( 217 void DetectorConstruction::SetCavityThickness(G4double value) 199 { 218 { 200 fCavityThickness = value; 219 fCavityThickness = value; 201 } 220 } 202 << 221 203 //....oooOO0OOooo........oooOO0OOooo........oo 222 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 204 223 205 void DetectorConstruction::SetCavityRadius(G4d 224 void DetectorConstruction::SetCavityRadius(G4double value) 206 { 225 { 207 fCavityRadius = value; << 226 fCavityRadius = value; 208 } << 227 } 209 228 210 //....oooOO0OOooo........oooOO0OOooo........oo 229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 211 230 212 void DetectorConstruction::SetCavityMaterial(c << 231 void DetectorConstruction::SetCavityMaterial(G4String materialChoice) 213 { 232 { 214 // search the material by its name << 233 // search the material by its name 215 G4Material* pttoMaterial = G4Material::GetMa << 234 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice); 216 if (pttoMaterial) fCavityMaterial = pttoMate 235 if (pttoMaterial) fCavityMaterial = pttoMaterial; >> 236 } >> 237 >> 238 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 239 >> 240 #include "G4RunManager.hh" >> 241 >> 242 void DetectorConstruction::UpdateGeometry() >> 243 { >> 244 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes()); 217 } 245 } 218 246 219 //....oooOO0OOooo........oooOO0OOooo........oo 247 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 220 248