DetectorConstruction.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "DetectorConstruction.hh"
00043 #include "DetectorMessenger.hh"
00044
00045 #include "G4Tubs.hh"
00046 #include "G4LogicalVolume.hh"
00047 #include "G4PVPlacement.hh"
00048
00049 #include "G4RunManager.hh"
00050
00051 #include "G4GeometryManager.hh"
00052 #include "G4PhysicalVolumeStore.hh"
00053 #include "G4LogicalVolumeStore.hh"
00054 #include "G4SolidStore.hh"
00055
00056 #include "G4VisAttributes.hh"
00057 #include "G4Colour.hh"
00058
00059 #include "G4UnitsTable.hh"
00060 #include "G4ios.hh"
00061
00062 #include "G4NistManager.hh"
00063
00064 #include "G4PhysicalConstants.hh"
00065 #include "G4SystemOfUnits.hh"
00066
00067
00068
00069 DetectorConstruction::DetectorConstruction()
00070 {
00071 fLogicTarget = 0;
00072 fLogicWorld = 0;
00073 fDetectorMessenger = new DetectorMessenger(this);
00074
00075 fRadius = 5.*cm;
00076 fLength = 10.*cm;
00077
00078 fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
00079 fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
00080 }
00081
00082
00083
00084 DetectorConstruction::~DetectorConstruction()
00085 {
00086 delete fDetectorMessenger;
00087 }
00088
00089 G4VPhysicalVolume* DetectorConstruction::Construct()
00090 {
00091
00092
00093 G4GeometryManager::GetInstance()->OpenGeometry();
00094 G4PhysicalVolumeStore::GetInstance()->Clean();
00095 G4LogicalVolumeStore::GetInstance()->Clean();
00096 G4SolidStore::GetInstance()->Clean();
00097
00098
00099 G4double worldR = fRadius + cm;
00100 G4double worldZ = fLength + cm;
00101
00102
00103
00104
00105 G4Tubs* solidW = new G4Tubs("World", 0., worldR, 0.5*worldZ, 0., twopi);
00106 fLogicWorld = new G4LogicalVolume(solidW, fWorldMaterial,"World");
00107 G4VPhysicalVolume* world = new G4PVPlacement(0, G4ThreeVector(),
00108 fLogicWorld, "World",
00109 0, false, 0);
00110
00111
00112
00113
00114 G4Tubs* solidA = new G4Tubs("Target", 0., fRadius, 0.5*fLength, 0.,twopi);
00115 fLogicTarget = new G4LogicalVolume( solidA, fTargetMaterial, "Target");
00116 new G4PVPlacement(0, G4ThreeVector(), fLogicTarget, "Target",
00117 fLogicWorld, false, 0);
00118
00119 G4cout << "### Target consist of "
00120 << fTargetMaterial->GetName()
00121 << " disks with R(mm)= " << fRadius/mm
00122 << " fLength(mm)= " << fLength/mm
00123 << " ###" << G4endl;
00124
00125
00126 fLogicWorld->SetVisAttributes(G4VisAttributes::Invisible);
00127
00128 G4VisAttributes* regCcolor = new G4VisAttributes(G4Colour(0., 0.3, 0.7));
00129 fLogicTarget->SetVisAttributes(regCcolor);
00130
00131 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
00132
00133 return world;
00134 }
00135
00136
00137
00138 void DetectorConstruction::SetTargetMaterial(const G4String& mat)
00139 {
00140
00141 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
00142
00143 if (material && material != fTargetMaterial) {
00144 fTargetMaterial = material;
00145 if(fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
00146 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
00147 }
00148 }
00149
00150
00151
00152 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
00153 {
00154
00155 G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
00156
00157 if (material && material != fWorldMaterial) {
00158 fWorldMaterial = material;
00159 if(fLogicWorld) fLogicWorld->SetMaterial(fWorldMaterial);
00160 G4RunManager::GetRunManager()->PhysicsHasBeenModified();
00161 }
00162 }
00163
00164
00165
00166 void DetectorConstruction::UpdateGeometry()
00167 {
00168 G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
00169 }
00170
00171
00172
00173 void DetectorConstruction::SetTargetRadius(G4double val)
00174 {
00175 if(val > 0.0 && val != fRadius) {
00176 fRadius = val;
00177 G4RunManager::GetRunManager()->GeometryHasBeenModified();
00178 }
00179 }
00180
00181
00182
00183 void DetectorConstruction::SetTargetLength(G4double val)
00184 {
00185 if(val > 0.0 && val != fLength) {
00186 fLength = val;
00187 G4RunManager::GetRunManager()->GeometryHasBeenModified();
00188 }
00189 }
00190
00191