Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 /// \file optical/OpNovice2/src/DetectorConstruction.cc 27 /// \brief Implementation of the DetectorConstruction class 28 // 29 // 30 // 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 33 34 #include "DetectorConstruction.hh" 35 36 #include "DetectorMessenger.hh" 37 38 #include "G4Box.hh" 39 #include "G4Element.hh" 40 #include "G4LogicalBorderSurface.hh" 41 #include "G4LogicalSkinSurface.hh" 42 #include "G4LogicalVolume.hh" 43 #include "G4Material.hh" 44 #include "G4NistManager.hh" 45 #include "G4OpticalSurface.hh" 46 #include "G4PVPlacement.hh" 47 #include "G4SystemOfUnits.hh" 48 #include "G4ThreeVector.hh" 49 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 52 DetectorConstruction::DetectorConstruction() 53 : G4VUserDetectorConstruction(), fDetectorMessenger(nullptr) 54 { 55 fTankMPT = new G4MaterialPropertiesTable(); 56 fWorldMPT = new G4MaterialPropertiesTable(); 57 fSurfaceMPT = new G4MaterialPropertiesTable(); 58 59 fSurface = new G4OpticalSurface("Surface"); 60 fSurface->SetType(dielectric_dielectric); 61 fSurface->SetFinish(ground); 62 fSurface->SetModel(unified); 63 fSurface->SetMaterialPropertiesTable(fSurfaceMPT); 64 65 fTankMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_WATER"); 66 fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR"); 67 68 fDetectorMessenger = new DetectorMessenger(this); 69 } 70 71 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 72 73 DetectorConstruction::~DetectorConstruction() 74 { 75 delete fTankMPT; 76 delete fWorldMPT; 77 delete fSurfaceMPT; 78 delete fSurface; 79 delete fDetectorMessenger; 80 } 81 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 83 84 G4VPhysicalVolume* DetectorConstruction::Construct() 85 { 86 fTankMaterial->SetMaterialPropertiesTable(fTankMPT); 87 fTankMaterial->GetIonisation()->SetBirksConstant(0.126 * mm / MeV); 88 89 fWorldMaterial->SetMaterialPropertiesTable(fWorldMPT); 90 91 // ------------- Volumes -------------- 92 // The experimental Hall 93 auto world_box = new G4Box("World", fExpHall_x, fExpHall_y, fExpHall_z); 94 95 fWorld_LV = new G4LogicalVolume(world_box, fWorldMaterial, "World"); 96 97 G4VPhysicalVolume* world_PV = 98 new G4PVPlacement(nullptr, G4ThreeVector(), fWorld_LV, "World", nullptr, false, 0); 99 100 // The tank 101 auto tank_box = new G4Box("Tank", fTank_x, fTank_y, fTank_z); 102 103 fTank_LV = new G4LogicalVolume(tank_box, fTankMaterial, "Tank"); 104 105 fTank = new G4PVPlacement(nullptr, G4ThreeVector(), fTank_LV, "Tank", fWorld_LV, false, 0); 106 107 // ------------- Surface -------------- 108 109 auto surface = new G4LogicalBorderSurface("Surface", fTank, world_PV, fSurface); 110 111 auto opticalSurface = 112 dynamic_cast<G4OpticalSurface*>(surface->GetSurface(fTank, world_PV)->GetSurfaceProperty()); 113 G4cout << "****** opticalSurface->DumpInfo:" << G4endl; 114 if (opticalSurface) { 115 opticalSurface->DumpInfo(); 116 } 117 G4cout << "****** end of opticalSurface->DumpInfo" << G4endl; 118 119 return world_PV; 120 } 121 122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 123 void DetectorConstruction::SetSurfaceSigmaAlpha(G4double v) 124 { 125 fSurface->SetSigmaAlpha(v); 126 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 127 128 G4cout << "Surface sigma alpha set to: " << fSurface->GetSigmaAlpha() << G4endl; 129 } 130 131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 132 void DetectorConstruction::SetSurfacePolish(G4double v) 133 { 134 fSurface->SetPolish(v); 135 G4RunManager::GetRunManager()->GeometryHasBeenModified(); 136 137 G4cout << "Surface polish set to: " << fSurface->GetPolish() << G4endl; 138 } 139 140 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 141 void DetectorConstruction::AddTankMPV(const G4String& prop, G4MaterialPropertyVector* mpv) 142 { 143 fTankMPT->AddProperty(prop, mpv); 144 G4cout << "The MPT for the box is now: " << G4endl; 145 fTankMPT->DumpTable(); 146 G4cout << "............." << G4endl; 147 } 148 149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 150 void DetectorConstruction::AddWorldMPV(const G4String& prop, G4MaterialPropertyVector* mpv) 151 { 152 fWorldMPT->AddProperty(prop, mpv); 153 G4cout << "The MPT for the world is now: " << G4endl; 154 fWorldMPT->DumpTable(); 155 G4cout << "............." << G4endl; 156 } 157 158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 159 void DetectorConstruction::AddSurfaceMPV(const G4String& prop, G4MaterialPropertyVector* mpv) 160 { 161 fSurfaceMPT->AddProperty(prop, mpv); 162 G4cout << "The MPT for the surface is now: " << G4endl; 163 fSurfaceMPT->DumpTable(); 164 G4cout << "............." << G4endl; 165 } 166 167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 168 void DetectorConstruction::AddTankMPC(const G4String& prop, G4double v) 169 { 170 fTankMPT->AddConstProperty(prop, v); 171 G4cout << "The MPT for the box is now: " << G4endl; 172 fTankMPT->DumpTable(); 173 G4cout << "............." << G4endl; 174 } 175 176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 177 void DetectorConstruction::AddWorldMPC(const G4String& prop, G4double v) 178 { 179 fWorldMPT->AddConstProperty(prop, v); 180 G4cout << "The MPT for the world is now: " << G4endl; 181 fWorldMPT->DumpTable(); 182 G4cout << "............." << G4endl; 183 } 184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 185 void DetectorConstruction::AddSurfaceMPC(const G4String& prop, G4double v) 186 { 187 fSurfaceMPT->AddConstProperty(prop, v); 188 G4cout << "The MPT for the surface is now: " << G4endl; 189 fSurfaceMPT->DumpTable(); 190 G4cout << "............." << G4endl; 191 } 192 193 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 194 void DetectorConstruction::SetWorldMaterial(const G4String& mat) 195 { 196 G4Material* pmat = G4NistManager::Instance()->FindOrBuildMaterial(mat); 197 if (pmat && fWorldMaterial != pmat) { 198 fWorldMaterial = pmat; 199 if (fWorld_LV) { 200 fWorld_LV->SetMaterial(fWorldMaterial); 201 fWorldMaterial->SetMaterialPropertiesTable(fWorldMPT); 202 } 203 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 204 G4cout << "World material set to " << fWorldMaterial->GetName() << G4endl; 205 } 206 } 207 208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 209 void DetectorConstruction::SetTankMaterial(const G4String& mat) 210 { 211 G4Material* pmat = G4NistManager::Instance()->FindOrBuildMaterial(mat); 212 if (pmat && fTankMaterial != pmat) { 213 fTankMaterial = pmat; 214 if (fTank_LV) { 215 fTank_LV->SetMaterial(fTankMaterial); 216 fTankMaterial->SetMaterialPropertiesTable(fTankMPT); 217 fTankMaterial->GetIonisation()->SetBirksConstant(0.126 * mm / MeV); 218 } 219 G4RunManager::GetRunManager()->PhysicsHasBeenModified(); 220 G4cout << "Tank material set to " << fTankMaterial->GetName() << G4endl; 221 } 222 } 223