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