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