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