00001
00002
00003
00004
00005
00006
00007 #include "DetectorConstruction.hh"
00008
00009 #include "G4Material.hh"
00010 #include "G4Box.hh"
00011 #include "G4Tubs.hh"
00012 #include "G4Trd.hh"
00013 #include "G4LogicalVolume.hh"
00014 #include "G4PVPlacement.hh"
00015 #include "G4RotationMatrix.hh"
00016
00017 #include "G4GeometryManager.hh"
00018 #include "G4PhysicalVolumeStore.hh"
00019 #include "G4LogicalVolumeStore.hh"
00020 #include "G4SolidStore.hh"
00021
00022 #include "G4VisAttributes.hh"
00023 #include "G4UnitsTable.hh"
00024
00025
00026
00027 DetectorConstruction::DetectorConstruction()
00028 {
00029 DefineMaterials();
00030
00031
00032
00033 m_cabinRadius = 50*cm;
00034 m_cabinLength = 80*cm;
00035 m_spacecraftThickness = 2*cm;
00036
00037 m_floorThickness = 2*cm;
00038
00039 m_astronautHeight = 50*cm;
00040 m_astronautTopWidth = 40*cm;
00041 m_astronautBottomWidth = 60*cm;
00042
00043 }
00044
00045
00046
00047 DetectorConstruction::~DetectorConstruction()
00048 { }
00049
00050
00051
00052 G4VPhysicalVolume* DetectorConstruction::Construct()
00053 {
00054 return ConstructVolumes();
00055 }
00056
00057
00058
00059 void DetectorConstruction::DefineMaterials()
00060 {
00061
00062
00063
00064 G4double Z,A,density;
00065
00066 G4Material* Al =
00067 new G4Material("Aluminium", Z=13., A=26.98*g/mole, density=2.700*g/cm3);
00068
00069
00070
00071
00072 G4Element* H = new G4Element("Hydrogen" ,"H" , Z=1., A= 1.01*g/mole);
00073 G4Element* N = new G4Element("Nitrogen" ,"N" , Z=7., A=14.01*g/mole);
00074 G4Element* O = new G4Element("Oxygen" ,"O" , Z=8., A=16.00*g/mole);
00075
00076 G4int ncomponents, natoms;
00077 G4double fractionmass;
00078
00079 G4Material* Air =
00080 new G4Material("Air", density= 1.290*mg/cm3, ncomponents=2);
00081 Air->AddElement(N, fractionmass=70.*perCent);
00082 Air->AddElement(O, fractionmass=30.*perCent);
00083
00084 G4Material* H2O =
00085 new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
00086 H2O->AddElement(H, natoms=2);
00087 H2O->AddElement(O, natoms=1);
00088
00089
00090
00091 G4Material* Vacuum =
00092 new G4Material("Galactic", Z=1., A=1.01*g/mole, density= 1.e-10*g/cm3,
00093 kStateGas, 2.73*kelvin, 3.e-18*pascal);
00094
00095
00096
00097 m_worldMaterial = Vacuum;
00098 m_spacecraftMaterial = m_floorMaterial = Al;
00099 m_cabinMaterial = Air;
00100 m_astronautMaterial = H2O;
00101
00102
00103
00104 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
00105 }
00106
00107
00108
00109 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
00110 {
00111
00112 G4GeometryManager::GetInstance()->OpenGeometry();
00113 G4PhysicalVolumeStore::GetInstance()->Clean();
00114 G4LogicalVolumeStore::GetInstance()->Clean();
00115 G4SolidStore::GetInstance()->Clean();
00116
00117
00118
00119 m_spacecraftRadius = m_cabinRadius + m_spacecraftThickness;
00120 m_spacecraftLength = m_cabinLength + 2*m_spacecraftThickness;
00121
00122 m_floorYcenter = - 0.5*m_cabinRadius;
00123 G4double floorYtop = m_floorYcenter + 0.5*m_floorThickness;
00124 G4double floorYbottom = m_floorYcenter - 0.5*m_floorThickness;
00125 m_floorWidth =
00126 2*std::sqrt(m_cabinRadius*m_cabinRadius - floorYbottom*floorYbottom);
00127 m_floorLength = m_cabinLength;
00128
00129 m_worldSizeXY = 2.2*m_spacecraftRadius;
00130 m_worldSizeZ = 1.1*m_spacecraftLength;
00131
00132 m_astronautPosition = floorYtop + 0.5*m_astronautHeight;
00133
00134
00135
00136
00137
00138 G4Box*
00139 solidWorld = new G4Box("World",
00140 m_worldSizeXY/2,m_worldSizeXY/2,m_worldSizeZ/2);
00141
00142 G4LogicalVolume*
00143 logicWorld = new G4LogicalVolume(solidWorld,
00144 m_worldMaterial,
00145 "World");
00146
00147 m_physiWorld = new G4PVPlacement(0,
00148 G4ThreeVector(),
00149 logicWorld,
00150 "World",
00151 0,
00152 false,
00153 0);
00154
00155
00156
00157 G4Tubs*
00158 solidSpacecraft = new G4Tubs("Spacecraft",
00159 0*cm, m_spacecraftRadius,
00160 0.5*m_spacecraftLength,
00161 0., twopi);
00162
00163 G4LogicalVolume*
00164 logicSpacecraft = new G4LogicalVolume(solidSpacecraft,
00165 m_spacecraftMaterial,
00166 "Spacecraft");
00167
00168 new G4PVPlacement(0,
00169 G4ThreeVector(0,0,0),
00170 logicSpacecraft,
00171 "Spacecraft",
00172 logicWorld,
00173 false,
00174 0);
00175
00176
00177
00178 G4Tubs*
00179 solidCabin = new G4Tubs("Cabin",
00180 0*cm, m_cabinRadius,
00181 0.5*m_cabinLength,
00182 0., 360*deg);
00183
00184 G4LogicalVolume*
00185 logicCabin = new G4LogicalVolume(solidCabin,
00186 m_cabinMaterial,
00187 "Cabin");
00188
00189 new G4PVPlacement(0,
00190 G4ThreeVector(0,0,0),
00191 logicCabin,
00192 "Cabin",
00193 logicSpacecraft,
00194 false,
00195 0);
00196
00197
00198
00199
00200 G4Box*
00201 solidFloor = new G4Box("Floor",
00202 m_floorWidth/2,m_floorLength/2,m_floorThickness/2);
00203
00204 G4LogicalVolume*
00205 logicFloor = new G4LogicalVolume(solidFloor, m_floorMaterial, "Floor");
00206
00207
00208 G4RotationMatrix* rotm1 = new G4RotationMatrix();
00209 rotm1->rotateX(90*deg);
00210
00211 new G4PVPlacement(rotm1,
00212 G4ThreeVector(0,m_floorYcenter,0),
00213 logicFloor,
00214 "Floor",
00215 logicCabin,
00216 false,
00217 0);
00218
00219
00220
00221
00222 G4Trd*
00223 solidAstronaut = new G4Trd("Astronaut",
00224 0.5 * m_astronautBottomWidth,
00225 0.5 * m_astronautTopWidth,
00226 0.5 * m_astronautBottomWidth,
00227 0.5 * m_astronautTopWidth,
00228 0.5 * m_astronautHeight);
00229
00230
00231 G4LogicalVolume*
00232 logicAstronaut = new G4LogicalVolume(solidAstronaut,
00233 m_astronautMaterial,
00234 "Astronaut");
00235
00236
00237 G4RotationMatrix* rotm2 = new G4RotationMatrix();
00238 rotm2->rotateX(90*deg);
00239
00240
00241 G4ThreeVector position = G4ThreeVector(0.,m_astronautPosition,0.);
00242
00243 new G4PVPlacement(rotm2,
00244 position,
00245 logicAstronaut,
00246 "Astronaut",
00247 logicCabin,
00248 false,
00249 0);
00250
00251
00252
00253 G4VisAttributes* colourWhite= new G4VisAttributes(G4Colour(1.,1.,1.));
00254 colourWhite->SetVisibility(true);
00255 colourWhite->SetForceSolid(false);
00256
00257 G4VisAttributes* colourGrey= new G4VisAttributes(G4Colour(0.5,0.5,0.5));
00258 colourGrey->SetVisibility(true);
00259 colourGrey->SetForceSolid(false);
00260
00261 G4VisAttributes* colourCyan= new G4VisAttributes(G4Colour(0.,1.,1.));
00262 colourCyan->SetVisibility(true);
00263 colourCyan->SetForceSolid(false);
00264
00265 G4VisAttributes* colourMagenta= new G4VisAttributes(G4Colour(1.,0.,1.));
00266 colourMagenta->SetVisibility(true);
00267 colourMagenta->SetForceSolid(true);
00268
00269 G4VisAttributes* colourBlue= new G4VisAttributes(G4Colour(0.,0.,1.));
00270 colourBlue->SetVisibility(true);
00271 colourBlue->SetForceSolid(false);
00272
00273 logicWorld->SetVisAttributes(colourGrey);
00274 logicSpacecraft->SetVisAttributes(colourCyan);
00275 logicCabin->SetVisAttributes(colourCyan);
00276 logicFloor->SetVisAttributes(colourWhite);
00277 logicAstronaut->SetVisAttributes(colourBlue);
00278
00279
00280
00281 PrintParameters();
00282
00283
00284
00285 return m_physiWorld;
00286 }
00287
00288
00289
00290 void DetectorConstruction::PrintParameters()
00291 {
00292 G4cout << "\n---------------------------------------------------------\n";
00293 G4cout
00294 << "---> World : (" << m_worldSizeXY/m << " X " << m_worldSizeXY/m << " X "
00295 << m_worldSizeZ/m << ") m of "
00296 << m_worldMaterial->GetName() << G4endl;
00297 G4cout
00298 << "---> Spacecraft : radius = " << G4BestUnit(m_spacecraftRadius,"Length")
00299 << "\t length = " << G4BestUnit(m_spacecraftLength,"Length")
00300 << "\t thickness = " << G4BestUnit(m_spacecraftThickness,"Length")
00301 << "\t material : " << m_spacecraftMaterial->GetName() << G4endl;
00302 G4cout
00303 << "---> Cabin : radius = " << G4BestUnit(m_cabinRadius,"Length")
00304 << "\t length = " << G4BestUnit(m_cabinLength,"Length")
00305 << "\t material : " << m_cabinMaterial->GetName() << G4endl;
00306 G4cout
00307 << "---> Floor : thickness = " << G4BestUnit(m_floorThickness,"Length")
00308 << "\t width = " << G4BestUnit(m_floorWidth,"Length")
00309 << "\t length = " << G4BestUnit(m_floorLength,"Length")
00310 << "\t material : " << m_floorMaterial->GetName() << G4endl;
00311 G4cout
00312 << "---> Astronaut : height = " << G4BestUnit(m_astronautHeight,"Length")
00313 << "\t bottom width = " << G4BestUnit(m_astronautBottomWidth,"Length")
00314 << "\t top width = " << G4BestUnit(m_astronautTopWidth,"Length")
00315 << "\t material : " << m_astronautMaterial->GetName() << G4endl;
00316 G4cout << "\n---------------------------------------------------------\n";
00317 G4cout << G4endl;
00318 }
00319
00320
00321
00322 void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
00323 {
00324
00325 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00326 if (pttoMaterial) m_worldMaterial = pttoMaterial;
00327 }
00328
00329
00330
00331 void DetectorConstruction::SetSpacecraftMaterial(G4String materialChoice)
00332 {
00333
00334 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00335 if (pttoMaterial) m_spacecraftMaterial = pttoMaterial;
00336 }
00337
00338
00339
00340 void DetectorConstruction::SetCabinMaterial(G4String materialChoice)
00341 {
00342
00343 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00344 if (pttoMaterial) m_cabinMaterial = pttoMaterial;
00345 }
00346
00347
00348
00349 void DetectorConstruction::SetFloorMaterial(G4String materialChoice)
00350 {
00351
00352 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00353 if (pttoMaterial) m_floorMaterial = pttoMaterial;
00354 }
00355
00356
00357
00358 void DetectorConstruction::SetAstronautMaterial(G4String materialChoice)
00359 {
00360
00361 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00362 if (pttoMaterial) m_astronautMaterial = pttoMaterial;
00363 }
00364
00365
00366
00367 #include "G4RunManager.hh"
00368
00369 void DetectorConstruction::UpdateGeometry()
00370 {
00371 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
00372 }
00373
00374