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