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" 36 37 37 #include "G4GeometryManager.hh" << 38 #include "G4LogicalVolume.hh" << 39 #include "G4LogicalVolumeStore.hh" << 40 #include "G4Material.hh" 38 #include "G4Material.hh" 41 #include "G4NistManager.hh" 39 #include "G4NistManager.hh" >> 40 >> 41 #include "G4Tubs.hh" >> 42 #include "G4LogicalVolume.hh" 42 #include "G4PVPlacement.hh" 43 #include "G4PVPlacement.hh" 43 #include "G4PhysicalConstants.hh" << 44 >> 45 #include "G4GeometryManager.hh" 44 #include "G4PhysicalVolumeStore.hh" 46 #include "G4PhysicalVolumeStore.hh" 45 #include "G4RunManager.hh" << 47 #include "G4LogicalVolumeStore.hh" 46 #include "G4SolidStore.hh" 48 #include "G4SolidStore.hh" >> 49 #include "G4RunManager.hh" >> 50 47 #include "G4SystemOfUnits.hh" 51 #include "G4SystemOfUnits.hh" 48 #include "G4Tubs.hh" << 52 #include "G4PhysicalConstants.hh" 49 #include "G4UnitsTable.hh" 53 #include "G4UnitsTable.hh" 50 54 51 //....oooOO0OOooo........oooOO0OOooo........oo 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 56 53 DetectorConstruction::DetectorConstruction() 57 DetectorConstruction::DetectorConstruction() 54 { << 58 :G4VUserDetectorConstruction(), 55 fTargetLength = 1 * cm; << 59 fTargetMater(0), fLogicTarget(0), 56 fTargetRadius = 0.5 * cm; << 60 fDetectorMater(0), fLogicDetector(0), 57 fDetectorLength = 5 * cm; << 61 fWorldMater(0), fPhysiWorld(0), 58 fDetectorThickness = 2 * cm; << 62 fDetectorMessenger(0) 59 << 63 { 60 fWorldLength = std::max(fTargetLength, fDete << 64 fTargetLength = 1*cm; >> 65 fTargetRadius = 0.5*cm; >> 66 fDetectorLength = 5*cm; >> 67 fDetectorThickness = 2*cm; >> 68 >> 69 fWorldLength = std::max(fTargetLength,fDetectorLength); 61 fWorldRadius = fTargetRadius + fDetectorThic 70 fWorldRadius = fTargetRadius + fDetectorThickness; 62 << 71 63 DefineMaterials(); 72 DefineMaterials(); 64 << 73 65 fDetectorMessenger = new DetectorMessenger(t 74 fDetectorMessenger = new DetectorMessenger(this); 66 } 75 } 67 76 68 //....oooOO0OOooo........oooOO0OOooo........oo 77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 69 78 70 DetectorConstruction::~DetectorConstruction() 79 DetectorConstruction::~DetectorConstruction() 71 { << 80 { delete fDetectorMessenger;} 72 delete fDetectorMessenger; << 73 } << 74 81 75 //....oooOO0OOooo........oooOO0OOooo........oo 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 76 83 77 G4VPhysicalVolume* DetectorConstruction::Const 84 G4VPhysicalVolume* DetectorConstruction::Construct() 78 { 85 { 79 return ConstructVolumes(); 86 return ConstructVolumes(); 80 } 87 } 81 88 82 //....oooOO0OOooo........oooOO0OOooo........oo 89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 83 90 84 void DetectorConstruction::DefineMaterials() 91 void DetectorConstruction::DefineMaterials() 85 { 92 { 86 // build materials 93 // build materials 87 // 94 // 88 fDetectorMater = new G4Material("Germanium", << 95 fDetectorMater = 89 << 96 new G4Material("Germanium", 32, 72.61*g/mole, 5.323*g/cm3); 90 G4Element* N = new G4Element("Nitrogen", "N" << 97 91 G4Element* O = new G4Element("Oxygen", "O", << 98 92 // << 99 G4Element* N = new G4Element("Nitrogen", "N", 7, 14.01*g/mole); 93 G4int ncomponents; << 100 G4Element* O = new G4Element("Oxygen", "O", 8, 16.00*g/mole); 94 G4double fractionmass; << 101 // 95 G4Material* Air20 = new G4Material("Air", 1. << 102 G4int ncomponents; G4double fractionmass; 96 293. * ke << 103 G4Material* Air20 = new G4Material("Air", 1.205*mg/cm3, ncomponents=2, 97 Air20->AddElement(N, fractionmass = 0.7); << 104 kStateGas, 293.*kelvin, 1.*atmosphere); 98 Air20->AddElement(O, fractionmass = 0.3); << 105 Air20->AddElement(N, fractionmass=0.7); >> 106 Air20->AddElement(O, fractionmass=0.3); 99 // 107 // 100 fWorldMater = Air20; 108 fWorldMater = Air20; 101 << 109 102 // or use G4 materials data base 110 // or use G4 materials data base 103 // 111 // 104 G4NistManager* man = G4NistManager::Instance << 112 G4NistManager* man = G4NistManager::Instance(); 105 fTargetMater = man->FindOrBuildMaterial("G4_ 113 fTargetMater = man->FindOrBuildMaterial("G4_CESIUM_IODIDE"); 106 << 114 107 /// G4cout << *(G4Material::GetMaterialTable << 115 ///G4cout << *(G4Material::GetMaterialTable()) << G4endl; 108 } 116 } 109 117 110 //....oooOO0OOooo........oooOO0OOooo........oo 118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 111 119 112 G4VPhysicalVolume* DetectorConstruction::Const 120 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes() 113 { 121 { 114 // Cleanup old geometry 122 // Cleanup old geometry 115 G4GeometryManager::GetInstance()->OpenGeomet 123 G4GeometryManager::GetInstance()->OpenGeometry(); 116 G4PhysicalVolumeStore::GetInstance()->Clean( 124 G4PhysicalVolumeStore::GetInstance()->Clean(); 117 G4LogicalVolumeStore::GetInstance()->Clean() 125 G4LogicalVolumeStore::GetInstance()->Clean(); 118 G4SolidStore::GetInstance()->Clean(); 126 G4SolidStore::GetInstance()->Clean(); 119 << 127 120 // World 128 // World 121 // 129 // 122 // (re) compute World dimensions if necessar 130 // (re) compute World dimensions if necessary 123 fWorldLength = std::max(fTargetLength, fDete << 131 fWorldLength = std::max(fTargetLength,fDetectorLength); 124 fWorldRadius = fTargetRadius + fDetectorThic 132 fWorldRadius = fTargetRadius + fDetectorThickness; 125 << 133 126 G4Tubs* sWorld = new G4Tubs("World", // nam << 134 G4Tubs* 127 0., fWorldRadius << 135 sWorld = new G4Tubs("World", //name 128 << 136 0.,fWorldRadius, 0.5*fWorldLength, 0.,twopi); //dimensions 129 G4LogicalVolume* lWorld = new G4LogicalVolum << 137 130 << 138 G4LogicalVolume* 131 << 139 lWorld = new G4LogicalVolume(sWorld, //shape 132 << 140 fWorldMater, //material 133 fPhysiWorld = new G4PVPlacement(0, // no ro << 141 "World"); //name 134 G4ThreeVecto << 142 135 lWorld, // << 143 fPhysiWorld = new G4PVPlacement(0, //no rotation 136 "World", // << 144 G4ThreeVector(), //at (0,0,0) 137 0, // mothe << 145 lWorld, //logical volume 138 false, // n << 146 "World", //name 139 0); // copy << 147 0, //mother volume 140 << 148 false, //no boolean operation >> 149 0); //copy number >> 150 141 // Target 151 // Target 142 // 152 // 143 G4Tubs* sTarget = new G4Tubs("Target", // n << 153 G4Tubs* 144 0., fTargetRadi << 154 sTarget = new G4Tubs("Target", //name 145 << 155 0., fTargetRadius, 0.5*fTargetLength, 0.,twopi); //dimensions 146 fLogicTarget = new G4LogicalVolume(sTarget, << 156 147 fTargetMa << 157 148 "Target") << 158 fLogicTarget = new G4LogicalVolume(sTarget, //shape 149 << 159 fTargetMater, //material 150 new G4PVPlacement(0, // no rotation << 160 "Target"); //name 151 G4ThreeVector(), // at (0 << 161 152 fLogicTarget, // logical << 162 new G4PVPlacement(0, //no rotation 153 "Target", // name << 163 G4ThreeVector(), //at (0,0,0) 154 lWorld, // mother volume << 164 fLogicTarget, //logical volume 155 false, // no boolean oper << 165 "Target", //name 156 0); // copy number << 166 lWorld, //mother volume >> 167 false, //no boolean operation >> 168 0); //copy number 157 169 158 // Detector 170 // Detector 159 // 171 // 160 G4Tubs* sDetector = << 172 G4Tubs* 161 new G4Tubs("Detector", fTargetRadius, fWor << 173 sDetector = new G4Tubs("Detector", >> 174 fTargetRadius, fWorldRadius, 0.5*fDetectorLength, 0.,twopi); >> 175 >> 176 >> 177 fLogicDetector = new G4LogicalVolume(sDetector, //shape >> 178 fDetectorMater, //material >> 179 "Detector"); //name >> 180 >> 181 new G4PVPlacement(0, //no rotation >> 182 G4ThreeVector(), //at (0,0,0) >> 183 fLogicDetector, //logical volume >> 184 "Detector", //name >> 185 lWorld, //mother volume >> 186 false, //no boolean operation >> 187 0); //copy number 162 188 163 fLogicDetector = new G4LogicalVolume(sDetect << 164 fDetect << 165 "Detect << 166 << 167 new G4PVPlacement(0, // no rotation << 168 G4ThreeVector(), // at (0 << 169 fLogicDetector, // logica << 170 "Detector", // name << 171 lWorld, // mother volume << 172 false, // no boolean oper << 173 0); // copy number << 174 189 175 PrintParameters(); 190 PrintParameters(); 176 << 191 177 // always return the root volume << 192 //always return the root volume 178 // 193 // 179 return fPhysiWorld; 194 return fPhysiWorld; 180 } 195 } 181 196 182 //....oooOO0OOooo........oooOO0OOooo........oo 197 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 183 198 184 void DetectorConstruction::PrintParameters() 199 void DetectorConstruction::PrintParameters() 185 { 200 { 186 G4cout << "\n Target : Length = " << G4BestU << 201 G4cout << "\n Target : Length = " << G4BestUnit(fTargetLength,"Length") 187 << " Radius = " << G4BestUnit(fTarget << 202 << " Radius = " << G4BestUnit(fTargetRadius,"Length") 188 << " Material = " << fTargetMater->Ge 203 << " Material = " << fTargetMater->GetName(); 189 G4cout << "\n Detector : Length = " << G4Bes << 204 G4cout << "\n Detector : Length = " << G4BestUnit(fDetectorLength,"Length") 190 << " Tickness = " << G4BestUnit(fDete << 205 << " Tickness = " << G4BestUnit(fDetectorThickness,"Length") 191 << " Material = " << fDetectorMater-> << 206 << " Material = " << fDetectorMater->GetName() << G4endl; 192 G4cout << "\n" << fTargetMater << "\n" << fD 207 G4cout << "\n" << fTargetMater << "\n" << fDetectorMater << G4endl; 193 } 208 } 194 209 195 //....oooOO0OOooo........oooOO0OOooo........oo 210 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 196 211 197 void DetectorConstruction::SetTargetMaterial(G 212 void DetectorConstruction::SetTargetMaterial(G4String materialChoice) 198 { 213 { 199 // search the material by its name 214 // search the material by its name 200 G4Material* pttoMaterial = G4NistManager::In << 215 G4Material* pttoMaterial = 201 << 216 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 202 if (pttoMaterial) { << 217 >> 218 if (pttoMaterial) { 203 fTargetMater = pttoMaterial; 219 fTargetMater = pttoMaterial; 204 if (fLogicTarget) { << 220 if(fLogicTarget) { fLogicTarget->SetMaterial(fTargetMater); } 205 fLogicTarget->SetMaterial(fTargetMater); << 206 } << 207 G4RunManager::GetRunManager()->PhysicsHasB 221 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 208 } << 222 } else { 209 else { << 223 G4cout << "\n--> warning from DetectorConstruction::SetTargetMaterial : " 210 G4cout << "\n--> warning from DetectorCons << 224 << materialChoice << " not found" << G4endl; 211 << " not found" << G4endl; << 225 } 212 } << 213 } 226 } 214 227 215 //....oooOO0OOooo........oooOO0OOooo........oo 228 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 216 229 217 void DetectorConstruction::SetDetectorMaterial 230 void DetectorConstruction::SetDetectorMaterial(G4String materialChoice) 218 { 231 { 219 // search the material by its name 232 // search the material by its name 220 G4Material* pttoMaterial = G4NistManager::In << 233 G4Material* pttoMaterial = 221 << 234 G4NistManager::Instance()->FindOrBuildMaterial(materialChoice); 222 if (pttoMaterial) { << 235 >> 236 if (pttoMaterial) { 223 fDetectorMater = pttoMaterial; 237 fDetectorMater = pttoMaterial; 224 if (fLogicDetector) { << 238 if(fLogicDetector) { fLogicDetector->SetMaterial(fDetectorMater); } 225 fLogicDetector->SetMaterial(fDetectorMat << 226 } << 227 G4RunManager::GetRunManager()->PhysicsHasB 239 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 228 } << 240 } else { 229 else { << 241 G4cout << "\n--> warning from DetectorConstruction::SetDetectorMaterial : " 230 G4cout << "\n--> warning from DetectorCons << 242 << materialChoice << " not found" << G4endl; 231 << " not found" << G4endl; << 243 } 232 } << 233 } 244 } 234 245 235 //....oooOO0OOooo........oooOO0OOooo........oo 246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 236 247 237 void DetectorConstruction::SetTargetRadius(G4d 248 void DetectorConstruction::SetTargetRadius(G4double value) 238 { 249 { 239 fTargetRadius = value; 250 fTargetRadius = value; 240 G4RunManager::GetRunManager()->ReinitializeG 251 G4RunManager::GetRunManager()->ReinitializeGeometry(); 241 } 252 } 242 253 243 //....oooOO0OOooo........oooOO0OOooo........oo 254 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 244 255 245 void DetectorConstruction::SetTargetLength(G4d 256 void DetectorConstruction::SetTargetLength(G4double value) 246 { 257 { 247 fTargetLength = value; 258 fTargetLength = value; 248 G4RunManager::GetRunManager()->ReinitializeG 259 G4RunManager::GetRunManager()->ReinitializeGeometry(); 249 } 260 } 250 261 251 //....oooOO0OOooo........oooOO0OOooo........oo 262 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 252 263 253 void DetectorConstruction::SetDetectorThicknes 264 void DetectorConstruction::SetDetectorThickness(G4double value) 254 { 265 { 255 fDetectorThickness = value; 266 fDetectorThickness = value; 256 G4RunManager::GetRunManager()->ReinitializeG 267 G4RunManager::GetRunManager()->ReinitializeGeometry(); 257 } 268 } 258 269 259 //....oooOO0OOooo........oooOO0OOooo........oo 270 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 260 271 261 void DetectorConstruction::SetDetectorLength(G 272 void DetectorConstruction::SetDetectorLength(G4double value) 262 { 273 { 263 fDetectorLength = value; 274 fDetectorLength = value; 264 G4RunManager::GetRunManager()->ReinitializeG 275 G4RunManager::GetRunManager()->ReinitializeGeometry(); 265 } 276 } 266 277 267 //....oooOO0OOooo........oooOO0OOooo........oo 278 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 268 279 269 G4double DetectorConstruction::GetTargetLength 280 G4double DetectorConstruction::GetTargetLength() 270 { 281 { 271 return fTargetLength; 282 return fTargetLength; 272 } 283 } 273 284 274 //....oooOO0OOooo........oooOO0OOooo........oo 285 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 275 286 276 G4double DetectorConstruction::GetTargetRadius 287 G4double DetectorConstruction::GetTargetRadius() 277 { 288 { 278 return fTargetRadius; 289 return fTargetRadius; 279 } 290 } 280 291 281 //....oooOO0OOooo........oooOO0OOooo........oo 292 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 282 293 283 G4Material* DetectorConstruction::GetTargetMat 294 G4Material* DetectorConstruction::GetTargetMaterial() 284 { 295 { 285 return fTargetMater; 296 return fTargetMater; 286 } 297 } 287 298 288 //....oooOO0OOooo........oooOO0OOooo........oo 299 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 289 300 290 G4LogicalVolume* DetectorConstruction::GetLogi 301 G4LogicalVolume* DetectorConstruction::GetLogicTarget() 291 { 302 { 292 return fLogicTarget; 303 return fLogicTarget; 293 } 304 } 294 305 295 //....oooOO0OOooo........oooOO0OOooo........oo 306 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 296 307 297 G4double DetectorConstruction::GetDetectorLeng 308 G4double DetectorConstruction::GetDetectorLength() 298 { 309 { 299 return fDetectorLength; 310 return fDetectorLength; 300 } 311 } 301 312 302 //....oooOO0OOooo........oooOO0OOooo........oo 313 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 303 314 304 G4double DetectorConstruction::GetDetectorThic 315 G4double DetectorConstruction::GetDetectorThickness() 305 { 316 { 306 return fDetectorThickness; 317 return fDetectorThickness; 307 } 318 } 308 319 309 //....oooOO0OOooo........oooOO0OOooo........oo 320 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 310 321 311 G4Material* DetectorConstruction::GetDetectorM 322 G4Material* DetectorConstruction::GetDetectorMaterial() 312 { 323 { 313 return fDetectorMater; 324 return fDetectorMater; 314 } 325 } 315 326 316 //....oooOO0OOooo........oooOO0OOooo........oo 327 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 317 328 318 G4LogicalVolume* DetectorConstruction::GetLogi 329 G4LogicalVolume* DetectorConstruction::GetLogicDetector() 319 { 330 { 320 return fLogicDetector; 331 return fLogicDetector; 321 } 332 } 322 333 323 //....oooOO0OOooo........oooOO0OOooo........oo 334 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 324 335