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